//importing controlP5 library to draw menus
import controlP5.*;


class GenreCheckBoxes {
  CheckBox checkbox;
  boolean showGenre;
  ControlP5 control;
  float[] oldCheckedState;
  
  GenreCheckBoxes(ControlP5 controlP5) {
    control = controlP5;
    checkbox = control.addCheckBox("Movie Genres", width-250, 40);
    //checkbox.setColorDeactive(color(#E33737));
    checkbox.setColorActive(color(#74BC22));
    checkbox.setColorLabel(color(255));
    //checkbox.setItemsPerRow(5);
    checkbox.setItemsPerRow(3);
    checkbox.setSpacingColumn(60);
    checkbox.setSpacingRow(10);
    // add items to a checkbox.
    checkbox.addItem("Action",0);
    checkbox.addItem("Adventure",1);
    checkbox.addItem("Animation",2);
    checkbox.addItem("Comedy",3);
    checkbox.addItem("Crime",4);
    checkbox.addItem("Documentary",5);
    checkbox.addItem("Drama",6);
    checkbox.addItem("Fantasy",7);
    checkbox.addItem("Family",8);
    checkbox.addItem("Film-Noir",9);
    checkbox.addItem("Horror",10);
    checkbox.addItem("Musical",11);
    checkbox.addItem("Mystery",12);
    checkbox.addItem("Romance",13);
    checkbox.addItem("Sci-Fi",14);
    checkbox.addItem("Thriller",15);
    checkbox.addItem("War",16);
    checkbox.addItem("Western",17);
    checkbox.addItem("All",18);
    
    showGenre = false;
    //checkbox.deactivateAll();
    checkbox.hide();
    oldCheckedState = new float[19];
    for (int i = 0; i < 19; i++)
      oldCheckedState[i] = 0;
    //button to reset genre selection
    control.addButton("Clear",0,width-120, 10, 80, 20);
    control.controller("Clear").hide();
    control.addButton("Genres",0,width-260, 10, 80, 20);
  }
  
  boolean getState(String name) {
    return checkbox.getState(name);
  }
  
  int getChosenCheckBox(float[] checkArray) {
    for (int i = 0; i < checkArray.length;i++) {
      if (oldCheckedState[i] != checkArray[i]) {
        oldCheckedState = checkArray;
        return i;
      }
    }
    return -1;
  }

  
  void toggle(int i) {
    checkbox.toggle(i);
  }
  
  void clear() {    
    for (int i = 0; i < 19; i++)
    {
       checkbox.deactivate(i);
       oldCheckedState[i] = 0;
    }
  }
  
  void toggleGenres() {
   if (showGenre) {  // hide the genres
     checkbox.hide();
     control.controller("Clear").hide();
     showGenre = false;
   } else {          // show the genres
     checkbox.show();
     //println("Genres will now be shown");
     control.controller("Clear").show();
     showGenre = true;
   }
 }
 
 public boolean isShown()
 {
   return showGenre;
 }
 
 void draw() {
  if (!showGenre)
     return;
 
  fill(0);
  rectMode(CORNERS);
  stroke(150, 100);
  strokeWeight(1);
  rect(width-265, 0, width-30, 200);
 }
 
}//class
